package su.mvc.service;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyFactory;
import com.googlecode.objectify.ObjectifyOpts;

import java.util.logging.Logger;

public class DaoSupport {

    private static final Logger log = Logger.getLogger(DaoSupport.class.getName());


    private ObjectifyFactory objectifyFactory;
    
    private Objectify objectify;

    public ObjectifyFactory getObjectifyFactory() {
        return objectifyFactory;
    }

    public void setObjectifyFactory(ObjectifyFactory objectifyFactory) {
        this.objectifyFactory = objectifyFactory;
    }

    public Objectify getObjectify() {
        if (objectify == null) {
            ObjectifyOpts opts = new ObjectifyOpts().setSessionCache(true);
            objectify = objectifyFactory.begin(opts);
        }
        return objectify;
    }

    public void setObjectify(Objectify objectify) {
        this.objectify = objectify;
    }
}
